package elevatronic.view;

import java.awt.Image;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JPanel;

/**
 * 
 * @author Benjamin CORNEC
 * This class represent an image
 */
public class ImageView {
	public final static String URL_PREFIX_DIR="sprite/";
	public final static String URL_ELEVATOR_DIR="buttons/elevator/";
	public final static String URL_FLOOR_DIR="buttons/floor/";
	public final static String URL_RIGHT_DIR="right/";
	public final static String URL_FILE_EXTENSION=".png";
	
	public final static String URL_BUILDING="building"; 
	public final static String URL_ELEVATOR="elevatorOpen"; 
	public final static String URL_FLOOR="floor"; 
	public final static String URL_PEOPLE1="people1"; 
	public final static String URL_PEOPLE2="people2"; 
	public final static String URL_PEOPLE3="people3"; 
	public final static String URL_BUTTON_ELEVATOR0="button0Elevator"; 
	public final static String URL_BUTTON_ELEVATOR1="button1Elevator"; 
	public final static String URL_BUTTON_ELEVATOR2="button2Elevator"; 
	public final static String URL_BUTTON_ELEVATOR3="button3Elevator"; 
	public final static String URL_BUTTON_ELEVATOR4="button4Elevator"; 
	public final static String URL_BUTTON_ELEVATOR5="button5Elevator"; 
	public final static String URL_BUTTON_ELEVATOR6="button6Elevator"; 
	public final static String URL_BUTTON_ELEVATOR7="button7Elevator"; 
	public final static String URL_BUTTON_ELEVATOR8="button8Elevator"; 
	public final static String URL_BUTTON_ELEVATOR9="button9Elevator"; 
	public final static String URL_BUTTON_ELEVATOR="buttonElevator"; 
	public final static String URL_BUTTON_DOWN_FLOOR="buttonDownFloor";
	public final static String URL_BUTTON_UP_FLOOR="buttonUpFloor"; 
	public final static String URL_BUTTON_FLOOR="buttonFloor"; 
	public final static String URL_BRAIN_PANEL="brainPanel";
	public final static String URL_PARAMETER_PANEL="parameterPanel";
	public final static String URL_TITLE_PANEL="titlePanel";
	public final static String URL_LEFT_PANEL="leftPanel"; 
	public final static String URL_RIGHT_PANEL="rightPanel"; 
	
	
	private static Map<String,Image> imageList;
	public static Map<String,Image> getImageList() {
		if (imageList==null){
			imageList=new HashMap<String, Image>();
			addImage(URL_BUILDING,URL_PREFIX_DIR+URL_BUILDING+URL_FILE_EXTENSION);
			addImage(URL_ELEVATOR,URL_PREFIX_DIR+URL_ELEVATOR+URL_FILE_EXTENSION);
			addImage(URL_FLOOR,URL_PREFIX_DIR+URL_FLOOR+URL_FILE_EXTENSION);
			addImage(URL_PEOPLE1,URL_PREFIX_DIR+URL_PEOPLE1+URL_FILE_EXTENSION);
			addImage(URL_PEOPLE2,URL_PREFIX_DIR+URL_PEOPLE2+URL_FILE_EXTENSION);
			addImage(URL_PEOPLE3,URL_PREFIX_DIR+URL_PEOPLE3+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_ELEVATOR0,URL_PREFIX_DIR+URL_ELEVATOR_DIR+URL_BUTTON_ELEVATOR0+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_ELEVATOR1,URL_PREFIX_DIR+URL_ELEVATOR_DIR+URL_BUTTON_ELEVATOR1+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_ELEVATOR2,URL_PREFIX_DIR+URL_ELEVATOR_DIR+URL_BUTTON_ELEVATOR2+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_ELEVATOR3,URL_PREFIX_DIR+URL_ELEVATOR_DIR+URL_BUTTON_ELEVATOR3+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_ELEVATOR4,URL_PREFIX_DIR+URL_ELEVATOR_DIR+URL_BUTTON_ELEVATOR4+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_ELEVATOR5,URL_PREFIX_DIR+URL_ELEVATOR_DIR+URL_BUTTON_ELEVATOR5+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_ELEVATOR6,URL_PREFIX_DIR+URL_ELEVATOR_DIR+URL_BUTTON_ELEVATOR6+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_ELEVATOR7,URL_PREFIX_DIR+URL_ELEVATOR_DIR+URL_BUTTON_ELEVATOR7+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_ELEVATOR8,URL_PREFIX_DIR+URL_ELEVATOR_DIR+URL_BUTTON_ELEVATOR8+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_ELEVATOR9,URL_PREFIX_DIR+URL_ELEVATOR_DIR+URL_BUTTON_ELEVATOR9+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_ELEVATOR,URL_PREFIX_DIR+URL_ELEVATOR_DIR+URL_BUTTON_ELEVATOR+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_DOWN_FLOOR,URL_PREFIX_DIR+URL_FLOOR_DIR+URL_BUTTON_DOWN_FLOOR+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_UP_FLOOR,URL_PREFIX_DIR+URL_FLOOR_DIR+URL_BUTTON_UP_FLOOR+URL_FILE_EXTENSION);
			addImage(URL_BUTTON_FLOOR,URL_PREFIX_DIR+URL_FLOOR_DIR+URL_BUTTON_FLOOR+URL_FILE_EXTENSION);
			addImage(URL_BRAIN_PANEL,URL_PREFIX_DIR+URL_RIGHT_DIR+URL_BRAIN_PANEL+URL_FILE_EXTENSION);
			addImage(URL_PARAMETER_PANEL,URL_PREFIX_DIR+URL_RIGHT_DIR+URL_PARAMETER_PANEL+URL_FILE_EXTENSION);
			addImage(URL_TITLE_PANEL,URL_PREFIX_DIR+URL_RIGHT_DIR+URL_TITLE_PANEL+URL_FILE_EXTENSION);
			addImage(URL_LEFT_PANEL,URL_PREFIX_DIR+URL_LEFT_PANEL+URL_FILE_EXTENSION);
			addImage(URL_RIGHT_PANEL,URL_PREFIX_DIR+URL_RIGHT_PANEL+URL_FILE_EXTENSION);
			
		}
		return imageList;
	}
	
	//get image by his name
	public static Image getImage(String imageUrl) {		
		return getImageList().get(imageUrl);
	}
	
	//facilitator to add an image
	public static void addImage(String name,String imageUrl){
		getImageList().put(name,new JPanel().getToolkit().getImage(imageUrl));
	}
	
	//the inner image
	private Image image;
	public Image getImage(){
		return image;
	}
	
	//x coordinate
	private int posX;
	public int getPosX() {
		return posX;
	}
	public void setPosX(int posX) {
		this.posX = posX;
	}
	
	//y coordinate
	private int posY;
	public int getPosY() {
		return posY;
	}
	public void setPosY(int posY) {
		this.posY = posY;
	}
	
	//width of the image
	private int wdth;
	public int getWdth() {
		return wdth;
	}
	
	//height of the image
	private int hght;	
	public int getHght() {
		return hght;
	}

	//visibility of the image
	private boolean visible;
	public boolean isVisible() {
		return visible;
	}
	public void setVisible(boolean visible) {
		this.visible = visible;
	}
	
	
	//constructor
	public ImageView(String imagePath,int posX, int posY, int wdth, int hght){
		//instantiate the image
		image = getImage(imagePath);
		this.posX=posX;
		this.posY=posY;
		this.wdth=wdth;
		this.hght=hght;
		this.visible=true;
	}
	
	
	
}
